/*
 * @Author: zws
 * @Date: 2021-05-28 17:08:59
 * @LastEditTime: 2021-06-08 16:05:37
 * @LastEditors: zws
 * @Description: 用户权限表控制类
 * @FilePath: \serve\src\controller\admin\RoleController.js
 */
import Roles from '@/db/models/Roles'
import { responseTemplate } from '@/utils/responseTemplate'
class RoleController {
    async getRoleList(ctx) {
        let { pageIndex, pageSize } = ctx.params;
        pageIndex = Number(pageIndex);
        pageSize = Number(pageSize);
        // 判断页码类型和值是否合法
        if (pageIndex !== pageIndex || pageSize !== pageSize || pageIndex <= 0 || pageSize <= 0) {
            ctx.body = responseTemplate('选择正确的页码', -1);
            return;
        }
        const count = await Roles.count(); // 获取数据总数
        // // 查找所有角色，并进行分页
        const records = await Roles.findAll({
            offset: (pageIndex - 1) * pageSize,
            limit: pageSize - 0
        })

        ctx.body = responseTemplate({
            records: records,
            total: count
        })
    }
    // TODO: 未实现提交功能;
    async postRole(ctx) {
        const body = ctx.request.body;

    }
}

export default new RoleController();